<?php
/* 竞拍首页 ajax处理
* @Author: ldm
* @Date:   2014-05-18 16:56:11
* @Last Modified by:   dm
* @Last Modified time: 2014-05-21 09:45:28
*/
// 判断是否为ajax请求
if(!(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest')){
	exit(0);
}

require_once "core.php";
require_once "paipai.class.php";
//error_reporting(E_ALL);
$core = new safe_weitao_plugin_iweitao_paipai;

// 显示的分类
if($core->_post('cat')){
	$cat = $core->_post('cat');

	$cat = $cat=='1' ? '' : ' where made=' . "'$cat'";

	// 查询分类
	$query = DB::query("select * from ". DB::table('paipai_goods') . "$cat" );
	$re = db_get_array($query);

	// 组合列表信息html输出
	$list = '';
	if(is_array($re)){
		foreach($re as $v){
			$img1 = '';
			if($v['status'] == 3){
				$img1 = "<img style='position:absolute;top:-100px;left:-110px' src='./source/plugin/iweitao_paipai/image/bg_deal_success.png'>";
			}
			$img2 = '';
			if($v['status'] == 2){
				$img2 = "<img style='position:relative;top:-180px;left:60px' src='./source/plugin/iweitao_paipai/image/bg_deal_miss.png'>";
			}

			$str = <<<STR
			<div class='loops' pub_time='{$v["pub_time"]}' origin_price='{$v["origin_price"]}' end_price='{$v["price"]}'>
				<div class='topicimg'>
					<a href='forum.php?mod=viewthread&tid={$v["tid"]}'>
					<img height='150' width='210' src='./data/attachment/forum/{$v["focus"]}' />
					</a>
				</div>
				<div class="pp_des">
					<p>编号:#001</p>
					<p><a href='forum.php?mod=viewthread&tid={$v["tid"]}'>{$v['title']}</a></p>
					<p>当前价格:{$v['price']}</p>
					
				</div>

				{$img1}
				{$img2}
				
			
				<div class="att_btns">
					<a href="javascript:void(0);" class="on_atten" title="关注"></a>
					<a href='forum.php?mod=viewthread&tid={$v["tid"]}' class="on_buy" title="出价" target="_blank"></a>
				</div>
			
				<div class="pp_status btn disabled">
					{$info}<br/>
					<!-- <strong>{$v['price']} <small>艺汇币</small></strong>
					<p class="text-muted">最新出价：ldm</p> -->
				</div>
			
			</div>
STR;
			$list .= $str;
		}
	}

	echo $list;


}elseif($core->_post('data')){//关注
	// 登录用户id
	$uid = $_G['uid'];
	if(!$uid){
		echo json_encode(array('status'=>-1));
		exit;
	}
	//处理参数
	$data = $core->_post('data');
	$darr = explode('-', trim($data,'-'));
	$gid = $darr[0];	//商品id
	$status = $darr[1] == 1 ? 0 : 1;	//将要设置的关注状态

	if($status == 1 ){//添加关注
		$query = DB::query("select gid from ".DB::table('paipai_attention') . " where gid='$gid' and uid='$uid'");
		// var_dump(db_get_one($query));exit;
		if(!db_get_one($query)){
			DB::query("replace into ".DB::table('paipai_attention') . "(uid,gid) values ('$uid','$gid')");
		}

	}else{//删除关注
		DB::query("delete from ".DB::table('paipai_attention') . " where gid='$gid' and uid='$uid'");

	}

	echo json_encode(array('status'=>$status,'gid'=>(int)$gid));

}


?>
